﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace 游戏平台原型
{
    public partial class loginwindow : UserControl
    {
        private NOPHandler m_showreg;//声明委托变量
        private NOPHandler m_showselectroom;//声明委托变量
        public loginwindow(NOPHandler showreg, NOPHandler showselectroom)
        {
            InitializeComponent();
            this.m_showreg = showreg;
            this.m_showselectroom = showselectroom;
        }
        private void btn_login_reg_Click(object sender, EventArgs e)
        {
            if (this.m_showreg != null)
            {
                this.m_showreg();
            }
        }

        private void btn_login_login_Click(object sender, EventArgs e)
        {
            Connection conn = new Connection();
            conn.sql("select id from userinfo where username='" + tb_login_username.Text + "' AND password='"+tb_login_password.Text+"'");
            if (!conn.dr.HasRows)
            {
                MessageBox.Show("用户名或密码错误！");
                conn.dr.Close();
                return;
            }
            if (this.m_showselectroom != null)
            {
                Lobby.Lobby1 = new Lobby(1);
                Lobby.currentlobby = 1;
                User.user = new User(tb_login_username.Text);
                User.user.loginin(User.user.currentuserno);
                this.m_showselectroom();
            }
        }
    }
}
